package com.dhcc.core.config;

import org.beetl.core.resource.FileResourceLoader;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.dhcc.core.config.properties.BeetlProperties;
import com.dhcc.core.config.properties.SysProperties;
import com.dhcc.core.framework.beetl.BeetlConfiguration;

/**
 * beetl 配置类
 * 
 * @ClassName: BeetlConfig
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月2日 上午9:41:52
 */
@Configuration
public class BeetlConfig {

    @Autowired
    BeetlProperties beetlProperties;
    
    @Autowired
    SysProperties sysProperties;

    /**
     * beetl的配置
     */
    @Bean(initMethod = "init")
    public BeetlConfiguration beetlConfiguration() {
        /*BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
        BeetlResourceLoader resourceLoader = new BeetlResourceLoader(sysProperties.getSysHome(),
                sysProperties.getBeetlViewPath());
        beetlConfiguration.setResourceLoader(resourceLoader);
        beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
        beetlConfiguration.setErrorHandler(new BeetlErrorHandler());*/
        
        BeetlConfiguration beetlConfiguration = new BeetlConfiguration();
        FileResourceLoader resourceLoader = new FileResourceLoader(sysProperties.getBeetlViewPath(),"utf-8");
        beetlConfiguration.setResourceLoader(resourceLoader);
        beetlConfiguration.setConfigProperties(beetlProperties.getProperties());
        
        
        return beetlConfiguration;
    }

    /**
     * beetl的视图解析器
     */
    @Bean
    public BeetlSpringViewResolver beetlViewResolver() {
        BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
        beetlSpringViewResolver.setConfig(beetlConfiguration());
        beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
        beetlSpringViewResolver.setOrder(0);
        return beetlSpringViewResolver;
    }
}
